#include "exifitem.h"
#include "exifhandler.h"
#include <QDesktopServices>

ExifItem::ExifItem(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
{
    m_exifHandler = new ExifHandler(this);
    connect(m_exifHandler,SIGNAL(gpsPosition(int,qreal,qreal)),this,SLOT(gpsPositionReady(int,qreal,qreal)));
}

void ExifItem::gpsPositionReady(int error , qreal longitude, qreal latitude)
{
    m_gpsError = error;
    emit gpsErrorChanged();
    m_latitude = latitude;
    m_longitude = longitude;
    emit positionChanged();
    launchMaps(m_latitude,m_longitude);
}

void ExifItem::getGpsPointer(QUrl filename)
{
    m_gpsError = 0;
    m_latitude = 0;
    m_longitude = 0;
    m_exifHandler->getImageGps(filename.toLocalFile());
}

void ExifItem::launchMaps(qreal latitude, qreal longitude)
{
    QDesktopServices::openUrl(QUrl("http://m.ovi.me/?c=" + QString::number(latitude) + "," + QString::number(longitude)));
}
